import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

// 防止两次路由切换产生的异常
const VueRouterPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err);
};

const routes = [
  {
    path: "/project",
    name: "project",
    component: () => import("@views/project"),
    children: [
      {
        path: "info/:id",
        name: "info",
        components: {
          pageview: () => import("@views/info")
        }
      },
      {
        path: "remind/:id",
        name: "remind",
        components: {
          pageview: () => import("@views/remind")
        }
      },
      {
        path: "record/:id",
        name: "record",
        components: {
          pageview: () => import("@views/record")
        }
      }
    ]
  },
  {
    path: "/",
    name: "login",
    component: () => import("@views/login")
  }
];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes
});

export default router;
